package com.dykj.apps.web.sysmanager.action;

import com.dykj.apps.web.core.BaseAction;
import com.dykj.apps.web.sysmanager.service.IGroupInfoBS;
import com.dykj.apps.web.sysmanager.dto.GroupInfoDTO;

import com.dykj.platform.framework.exception.ApplicationException;
import com.googlecode.jsonplugin.annotations.JSON;

import java.util.List;
import java.util.Map;

public class GroupInfoOrgAction extends BaseAction{

	private static final long serialVersionUID = -6419884952920676104L;
	
	private List nodes;
	private GroupInfoDTO groupInfoDTO = new GroupInfoDTO();
	private IGroupInfoBS bs;
	private Map groupmap;
	private String funMethod;

	/**
	 * 取得树形功能菜单
	 * @return
	 * @throws ApplicationException
	 */
	public String queryGroupInfo() throws ApplicationException{
		nodes = bs.getGroupInfo(groupInfoDTO.getGroupid());
		return "success";
	}
	/**
	 * 初始化
	 * @return
	 * @throws ApplicationException
	 */
	public String initGroupInfoOrg() throws ApplicationException{
		this.request("init", "true");
		return "initGroupInfoOrg";		
	}
	
	public String queryManagerGroupInfo() throws ApplicationException{
		nodes = bs.getManagerGroupInfo(groupInfoDTO.getGroupid());
		return "success";
	}
	/**
	 * 初始化右边填写栏
	 * @return
	 * @throws ApplicationException
	 */
	public String initGroupInfoRight() throws ApplicationException{
		groupmap = bs.getGroupMap(groupInfoDTO.getGroupid());
		return "modifyGroupInfo";
	}
	/**
	 * 初始化修改机构信息
	 * @return
	 * @throws ApplicationException
	 */
	public String modifyGroupInfo() throws ApplicationException{
		groupInfoDTO = bs.getGroupInfoDTO(groupInfoDTO.getGroupid());
		this.request("editable", "true");
		groupmap = bs.getGroupMap(groupInfoDTO.getGroupid());
		return "modifyGroupInfo";
	}
	
	/**
	 * 保存或更新
	 * @return
	 * @throws ApplicationException
	 */
	public String saveGroupInfo() throws ApplicationException{
		if(null==groupInfoDTO.getGroupid()||"".equals(groupInfoDTO.getGroupid())){
			funMethod="add";
		}else{
			funMethod="update";
		}
		bs.saveOrUpdateGroupInfo(groupInfoDTO);
		funMethod=funMethod+";"+groupInfoDTO.getGroupid();
		alert("保存成功！");
		return "success";
	}
	
	/**
	 * 初始化增加子节点
	 * @return
	 * @throws ApplicationException
	 */
	public String addSubGroupInfo()throws ApplicationException{
		String parentid = groupInfoDTO.getGroupid();
		groupInfoDTO = new GroupInfoDTO();
		groupInfoDTO.setParentid(parentid);
		groupmap = bs.getGroupMap(groupInfoDTO.getGroupid());
		return "modifyGroupInfo";
	}
	
	/**
	 * 删除机构
	 * @return
	 * @throws ApplicationException
	 */
	public String delGroupInfo()throws ApplicationException{
		int flag = bs.delGroupInfo(groupInfoDTO.getGroupid());
		if(flag<0){
			funMethod="error";
		}else{
			funMethod="success";
		}
		return "success";
	}
	/*
	 * ================================get set方法=====================================
	 */	
	@JSON(serialize=false)
	public IGroupInfoBS getBs() {
		return bs;
	}
	public void setBs(IGroupInfoBS bs) {
		this.bs = bs;
	}
	@JSON(serialize=false)
	public GroupInfoDTO getGroupInfoDTO() {
		return groupInfoDTO;
	}

	public void setGroupInfoDTO(GroupInfoDTO groupInfoDTO) {
		this.groupInfoDTO = groupInfoDTO;
	}

	public Object getModel() {
		return groupInfoDTO;
	}
	public List getNodes() {
		return nodes;
	}

	public void setNodes(List nodes) {
		this.nodes = nodes;
	}

	public Map getGroupmap() {
		return groupmap;
	}

	public void setGroupmap(Map groupmap) {
		this.groupmap = groupmap;
	}
	public String getFunMethod() {
		return funMethod;
	}

	public void setFunMethod(String funMethod) {
		this.funMethod = funMethod;
	}
}
